import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';

@Component({
	selector: 'm-switch-checkbox',
	templateUrl: './switch-checkbox.component.html',
	styleUrls: ['./switch-checkbox.component.scss'],
	providers: [
		{
			provide: NG_VALUE_ACCESSOR,
			useExisting: SwitchCheckboxComponent,
			multi: true,
		},
	],
})
export class SwitchCheckboxComponent implements OnInit, ControlValueAccessor {
	constructor() {}
	@Input() disabled = false;
	@Input() value: boolean;
	@Output() valueChange = new EventEmitter<boolean>();
	ngOnInit() {}
	change() {
		this.value = !this.value;
		this.valueChange.emit(this.value);
	}
	writeValue(obj: any): void {
		this.value = obj;
	}
	registerOnChange(fn: any): void {
		this.valueChange.subscribe(fn);
	}
	registerOnTouched(fn: any): void {
		this.valueChange.subscribe(fn);
	}
	setDisabledState?(isDisabled: boolean): void {
		this.disabled = isDisabled;
	}
}
